import { defineStore } from "pinia"

interface ContentType {
  blockdiag: string;
  bpmn: string;
  bytefield: string;
  seqdiag: string;
  actdiag: string;
  nwdiag: string;
  packetdiag: string;
  rackdiag: string;
  c4plantuml: string;
  d2: string;
  dbml: string;
  ditaa: string;
  erd: string;
  excalidraw: string;
  graphviz: string;
  mermaid: string;
  nomnoml: string;
  pikchr: string;
  plantuml: string;
  structurizr: string;
  svgbob: string;
  symbolator: string;
  tikz: string;
  vega: string;
  vegalite: string;
  wavedrom: string;
  wireviz: string;
}

// 定义 state 的类型
type DrawStoreState = {
  format: string;
  content: ContentType;
};

export const useDrawStore = defineStore('drawStore', {
  state: (): DrawStoreState => ({
    format: '',
    content: {
      blockdiag: '',
      bpmn: '',
      bytefield: '',
      seqdiag: '',
      actdiag: '',
      nwdiag: '',
      packetdiag: '',
      rackdiag: '',
      c4plantuml: '',
      d2: '',
      dbml: '',
      ditaa: '',
      erd: '',
      excalidraw: '',
      graphviz: '',
      mermaid: '',
      nomnoml: '',
      pikchr: '',
      plantuml: '',
      structurizr: '',
      svgbob: '',
      symbolator: '',
      tikz: '',
      vega: '',
      vegalite: '',
      wavedrom: '',
      wireviz: ''
    }
  }),
  actions: {
    setFormat(format: string) {
      this.format = format;
    },
    setContent(format: keyof ContentType, content: string) {
      this.content[format] = content;
    }
  },
  getters: {
    getFormat: (state: DrawStoreState) => {
      return state.format;
    },
    getContent: (state: DrawStoreState) => {
      return state.content[state.format as keyof ContentType];
    }
  }
})

